    var drawDataSource;


    var film = {
        //设置谷歌影像 
        setImagery: function (parm) {
            var imageryLayers = viewer.imageryLayers;
            if (parm == "google" || !!!parm) {
                viewer.imageryLayers.remove(viewer.imageryLayers.get(1));
                var google = new LSGlobe.UrlTemplateImageryProvider({
                    url: 'http://mt0.google.cn/vt/lyrs=s&hl=zh-CN&x={x}&y={y}&z={z}',
                    tilingScheme: new LSGlobe.WebMercatorTilingScheme(),
                    maximumLevel: 20
                });
                google.name = "google";
                viewer.imageryLayers.addImageryProvider(google, 1);
            } else if (parm == "tianditu") {
                viewer.imageryLayers.remove(viewer.imageryLayers.get(1));

                var tianditu = new LSGlobe.WebMapTileServiceImageryProvider({
                    url: 'http://t0.tianditu.com/img_c/wmts?service=WMTS&version=1.0.0&request=GetTile&tilematrix={TileMatrix}&layer=img&style={style}&tilerow={TileRow}&tilecol={TileCol}&tilematrixset={TileMatrixSet}&format=tiles',
                    layer: 'img',
                    style: 'default',
                    format: 'tiles',
                    tileMatrixSetID: 'c',
                    subdomains: ['t0', 't1', 't2', 't3', 't4', 't5', 't6', 't7'],
                    maximumLevel: 18,
                    tilingScheme: new LSGlobe.GeographicTilingScheme(),
                    tileMatrixLabels: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19']
                });
                tianditu.name = "tianditu";
                imageryLayers.addImageryProvider(tianditu, 1);

            } else if (parm == "bingmap") {
                viewer.imageryLayers.remove(viewer.imageryLayers.get(1));

                var bing = new LSGlobe.BingMapsImageryProvider({
                    url: 'https://dev.virtualearth.net',
                    key: 'Ak1xFbfMYLAAsWU7cZMRyvDHY13HFN1PESWP98WJLoK49OQDb8HSeUjBV3MpC5Yf',
                    mapStyle: LSGlobe.BingMapsStyle.AERIAL
                });
                bing.name = "bingmap";
                imageryLayers.addImageryProvider(bing, 1);
            }
        },
        imageryUiControl: function (parm, parmtype) {
            //影像地形ui驱动
            if (parmtype == "1") {
                if (!!parm) {
                    $("#ImageryLayer-box .ImageryLayer-item[data=" + parm + "]").addClass("active");
                } else {
                    //默认无影像$("#ImageryLayer-box .ImageryLayer-item[data=google]").addClass("active");
                }
            } else {
                if (!!parm) {
                    $("#terrain-box .ImageryLayer-item[data=" + parm + "]").addClass("active");
                } else {
                    $("#terrain-box .ImageryLayer-item[data=none]").addClass("active");
                }
            }
        },
        getPrimitiveById: function (primitiveid) {
            //获取倾斜并加载到场景中||obj 
            var aPrimitives = viewer.scene.primitives;
            var oPrimitive;
            for (var i = 0; i < aPrimitives._primitives.length; i++) {
                if (!!aPrimitives._primitives[i].name) {
                    if (aPrimitives._primitives[i].name.guid == primitiveid) {
                        oPrimitive = aPrimitives._primitives[i];
                        break;
                    };
                }
            }
            return oPrimitive;
        },
        serviceUiControl: function (oservice) {
            //加载数据[图层管理]
            var servertype = oservice.serverType;
            var sItem = "";
            sItem += "<div class=\"layer-item-title\" guid=\"" + oservice.guid + "\" type=\"" + servertype + "\">";
            var sIconStyle;

            if (servertype == "1") {
                sIconStyle = "icon-qing";
            } else if (servertype == "2") {
                sIconStyle = "icon-chuan";
                var model = aObj[oservice.guid];
                $.ajax({
                    url: basePath + "/getPropByServerId.action",
                    type: "post",
                    data: "serverGuid=" + oservice.guid,
                    async: false,
                    dataType: "Json",
                    success: function (result) {
                        if (result.resultCode == "1") {
                            if (!result.serverprop || result.serverprop.underground == 2) {
                                model.name.underground = 2;
                            } else {
                                model.name.underground = 1;
                                model.show = false;
                            }
                        } else {
                            console.log(result.resultMsg)
                        }
                    },
                    error: function (err) {
                        console.log(err);
                    }
                })
            } else if (servertype == "3") {
                sIconStyle = "icon-shp";
            } else if (servertype == "4") {
                sIconStyle = "icon-lrp";
            }
            sItem += "<i class=\"\"></i>";
            sItem += "<i class=\"checkicon active\"></i>";
            sItem += "<i class=\"typeicon " + sIconStyle + "\"></i>";
            sItem += "<span>" + oservice.title + "</span>";
            sItem += "<\/div>";
            $("#sceneBox").prepend($(sItem));
        },
        loadWidget: function () {
            //初始加载标绘
            var allDataSource = viewer.dataSources._dataSources;
            var isHaveAttach = false;
            for (var a = 0; a < allDataSource.length; a++) {
                if (allDataSource[a]._sourceUri.indexOf("draw.geojson") != -1) {
                    drawDataSource = allDataSource[a];
                    var entities = drawDataSource.entities._entities._array;
                    for (var i = 0; i < entities.length; i++) {
                        var entity = entities[i];
                        var entityType = entity.properties["polygonType"]._value;
                        var ParentId = entity.properties["parentId"]._value;
                        var ParentName = entity.properties["parentName"]._value;
                        var WidgetId = entity.id;
                        currentWidgetId = ParentId;
                        var ParentHave = $("#" + ParentId).length;
                        var WidgetName = entity.name;
                        if (ParentHave <= 0 && ParentId != dataGuid) {
                            addWidgetDoc(ParentId, ParentName);
                        }
                        if (entityType == "point") {
                            var WidgetColor = entity.properties["marker-color"]._value;
                            addWidget(WidgetId, "point", WidgetColor, WidgetName);
                        } else if (entityType == "line") {
                            var WidgetColor = entity.properties["stroke"]._value;
                            addWidget(WidgetId, "line", WidgetColor, WidgetName);
                        } else if (entityType == "polygon") {
                            var WidgetColor = entity.properties["fill"]._value;
                            var WidgetName = entity.name;
                            addWidget(WidgetId, "polygon", WidgetColor, WidgetName);
                        }
                        var WidgetLength = $("#widgetBox>div").length;
                        if (WidgetLength <= 0) {
                            $("#Widget").remove();
                        }
                    }
                    isHaveAttach = true;
                }
            }
            if (!isHaveAttach) {
                var sTimeSecondes = new Date().getTime();
                var geojsonUrl = getRootPath() + "/attach/" + dataGuid + "/draw.geojson?" + sTimeSecondes;
                var promise = LSGlobe.GeoJsonDataSource.load(geojsonUrl, {
                /* clampToGround : true,
                attachPolygon : true */
            });
            promise.then(function (dataSource) {
                drawDataSource = dataSource;
                viewer.dataSources.add(dataSource);
                var entities = dataSource.entities._entities._array;
                for (var i = 0; i < entities.length; i++) {
                    var entity = entities[i];
                    var entityType = entity.properties["polygonType"]._value;
                    var ParentId = entity.properties["parentId"]._value;
                    var ParentName = entity.properties["parentName"]._value;
                    var WidgetId = entity.id;
                    currentWidgetId = ParentId;
                    var ParentHave = $("#" + ParentId).length;
                    var WidgetName = entity.name;
                    if (ParentHave <= 0 && ParentId != dataGuid) {
                        film.addWidgetDoc(ParentId, ParentName);
                    }
                    if (entityType == "point") {
                        var WidgetColor = entity.properties["marker-color"]._value;
                        film.addWidget(WidgetId, "point", WidgetColor, WidgetName);
                    } else if (entityType == "line") {
                        var WidgetColor = entity.properties["stroke"]._value;
                        film.addWidget(WidgetId, "line", WidgetColor, WidgetName);
                    } else if (entityType == "polygon") {
                        var WidgetColor = entity.properties["fill"]._value;
                        var WidgetName = entity.name;
                        film.addWidget(WidgetId, "polygon", WidgetColor, WidgetName);
                    }
                    var WidgetLength = $("#widgetBox>div").length;
                    if (WidgetLength <= 0) {
                        $("#Widget").remove();
                    }
                }
            }).otherwise(function (error) {
                $("#Widget").remove();
            });
        }
    },
    addWidgetDoc: function (oId, name) {
        //添加标绘列表 
        var oDocHtml = "";
        oDocHtml += "<div class=\"layer-item widget active\" id=\"" + oId + "\">";
        oDocHtml += "	 <div class=\"layer-item-title\">";
        oDocHtml += "		<i class=\"arrow active\"></i>";
        oDocHtml += "		<i class=\"checkicon box active\"></i>";
        oDocHtml += "		<i class=\"typeicon icon-doc\"></i>";
        oDocHtml += "		<span>" + name + "</span>";
        oDocHtml += "	 </div>";
        oDocHtml += "  <div class=\"layer-item-content widgetBox\" style=\"display:none;\">";
        oDocHtml += "  </div>";
        oDocHtml += "</div>";
        $("#widgetBox").append(oDocHtml);
    },
    addWidget: function (oId, otype, Color, name, parentId) {
        // 添加点标绘到列表 
        var oPointHtml = "";
        oPointHtml += "<div class=\"layer-item-title wid\" id=\"" + oId + "\">";
        oPointHtml += "<i class=\"\"></i>";
        oPointHtml += "<i class=\"checkicon active\"></i>";
        if (otype == "point") {
            oPointHtml += "<i class=\"typeicon " + otype + "\" style=\"position:relative;overflow:hidden;\"><i style=\" position: absolute;left: -12px;top: 0;background-image: url(../manage/images/icon-wigetpoint.png);filter: drop-shadow(" + Color + " 12px 0px);\"></i></i>";
        } else {
            oPointHtml += "<i class=\"typeicon " + otype + "\" style=\"background-color:" + Color + ";\"></i>";
        }

        /* oPointHtml+="<i class=\"typeicon "+otype+"\" style=\"background-color:"+Color+";\"><i></i></i>"; */
        oPointHtml += "<span>" + name + "</span>";
        oPointHtml += "</div>";
        if (currentWidgetId == dataGuid) {
            $("#widgetBox").prepend(oPointHtml);
        } else {
            $("#" + currentWidgetId).find(".widgetBox").prepend(oPointHtml);
        }
    }
}